package agents.interaction;

import extra.Position;
import game.constants.ReferenceAgent;
import game.constants.ReferenceObject;
import game.constants.ReferenceSpecialFeature;
import interfaces.impl.HumanInteraction;
import objects.SpetialFeature;
import objects.WorldObject;
import universe.Universe;
import actions.ActionBuildStarcraftObject;
import actions.ActionXYtoMove;

public class InteractionBuildAcademy extends HumanInteraction{
		
		private ActionXYtoMove actionXYtoMove;
		private ActionBuildStarcraftObject actionBuildStarcraftObject;
		
		private Position position;
		
		SpetialFeature academyPrice;
		SpetialFeature attackRange;
		
		SpetialFeature xToMove;
		SpetialFeature yToMove;

		@Override
		public void initializeParametersList() {
			position=new Position();
			addParameter(position);
			
		}

		@Override
		public void initializeActionList() {
			actionXYtoMove= new ActionXYtoMove();
			addAction(actionXYtoMove);
			
			actionBuildStarcraftObject=new ActionBuildStarcraftObject();
			addAction(actionBuildStarcraftObject);
			
		}

		@Override
		public void initializeSpecialFeatures() {
			
			academyPrice= new SpetialFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_ACADEMY_PRICE);
			addSpetialFeature(academyPrice);
			
			attackRange= new SpetialFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_ATTACK_RANGE);
			addSpetialFeature(attackRange);
			
			xToMove = new SpetialFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_X_TO_MOVE);
			addSpetialFeature(xToMove);
			
			yToMove = new SpetialFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_Y_TO_MOVE);
			addSpetialFeature(yToMove);
			
			
		}

		@Override
		public void initializeName() {
			name="Build ACADEMY";
			
		}

		@Override
		public void initializeId() {
			id=ReferenceAgent.AGENT_HUMAN_INTERACTION_BUILD_ACADEMY;
			
		}

		@Override
		public void updateChild(WorldObject object, Universe universe, double time) {
			
			object.desactivateAllHumanInteractions();
			isActive=true;
			
			double distance = (Position.DistanceBetween(object.getPosition(), position));
			
			if(distance>attackRange.getValue()){
				if(xToMove.getValue()==position.getX() && yToMove.getValue()==position.getY()){
					return;
				}
				actionXYtoMove.setSource(object);
				actionXYtoMove.setTarget(object);
				actionXYtoMove.setPosition(position);
				universe.setAction(actionXYtoMove);
				return;
			}	
			if(xToMove.getValue()==position.getX() && yToMove.getValue()==position.getY()){
				actionBuildStarcraftObject.setSource(object);
				actionBuildStarcraftObject.setTarget(object);
				actionBuildStarcraftObject.setPosition(position);
				actionBuildStarcraftObject.setPrice(academyPrice.getValue());
				actionBuildStarcraftObject.setObjectReference(ReferenceObject.OBJECT_REFERENCE_ACADEMY1);
				universe.setAction(actionBuildStarcraftObject);
				
				isActive=false;
				}
			
		}
	
}
